package logic

import (
	"context"
	"houses_srv/housesclient"
	"houses_srv/models"

	"houses_srv/houses"
	"houses_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLookHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLookHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLookHouseLogic {
	return &ListLookHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLookHouseLogic) ListLookHouse(in *houses.ListLookHouseRequest) (*houses.ListLookHouseResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var lh models.LookHouse
	lh.UserId = int(in.UserId)
	id, err := lh.ListLookHouseByUserId()
	if err != nil {
		return nil, err
	}

	var h models.House
	var houseList []*housesclient.ListHouse
	for _, house := range id {
		h.ID = uint(house.HouseId)
		listHouse, err := h.ListHouse()
		if err != nil {
			return nil, err
		}

		for _, v := range listHouse {
			list := housesclient.ListHouse{
				HouseId:   int64(v.ID),
				Title:     v.Title,
				Image:     v.Image,
				Price:     int64(v.Price),
				Fool:      float32(v.Fool),
				HouseType: v.HouseType,
			}
			houseList = append(houseList, &list)
		}
	}

	return &houses.ListLookHouseResponse{
		LookHouseId: int64(lh.ID),
		Time:        lh.Time,
		Comment:     lh.Comment,
		List:        houseList,
	}, nil
}
